<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>评论列表</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.css">
</head>
<body>
 <div class="container">
     <div class="row">
         <div class="col-md-12">
                <form onsubmit="login(event)">
                        <div class="form-group">
                            <label for="username">用户名</label>
                            <input type="text" id="username" name="username" class="form-control" placeholder="用户名"/>
                        </div>
                        <div class="form-group">
                            <label for="password">密码</label>
                            <input type="text" id="password" name="password" class="form-control" placeholder="密码"/>
                        </div>
                        <div class="form-group">
                            <input type="submit" class="btn btn-primary" value="登录">
                        </div>
                    </form>
         </div>
     </div>
 </div>  
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
function login(event){
   event.preventDefault();
   let username = $('#username').val();
   let password = $('#password').val();
   $.post('/api/login',{username,password}).then(result=>{
       if(result.code ==0){
         location.href = `/user.html?username=${username}`;
       }
       $('#username').val('');
       $('password').val('');
   });
}
</script>
</body>
</html>